﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Stamp_For_Africa_Version_2.Models;
using Stamp_For_Africa_Version_2.Repositories;

namespace Stamp_For_Africa_Version_2.Controllers
{
    public class ColoursController : Controller
    {
			readonly ColourRepository _colourRepository = new ColourRepository();

			#region HTTP - GET Methods

			//
			// GET: /Colours/

			public ActionResult Index()
			{

				var colours = _colourRepository.FindAllColours().ToList();

				return View("Index", colours);
			}

			//
			// GET: /Colours/Details/Id

			public ActionResult Details(Guid id)
			{

				Colour colour = _colourRepository.GetColour(id);

				if (colour == null)
					return View("NotFound");
				else
					return View("Details", colour);
			}

			//
			// GET: /Colours/Create

			public ActionResult Create()
			{

				Colour colour = new Colour()
				{

				};

				return View(colour);
			}

			//
			// GET: /Colours/Edit/xxx

			public ActionResult Edit(Guid id)
			{

				Colour colour = _colourRepository.GetColour(id);

				return View(colour);
			}


			//
			// GET: /Artists/Delete/xxx

			public ActionResult Delete(Guid id)
			{

				Colour colour = _colourRepository.GetColour(id);

				if (colour == null)
					return View("NotFound");
				else
					return View(colour);
			}

			#endregion

			#region HTTP - POST Methods

			//
			// POST: /Country/Create

			[AcceptVerbs(HttpVerbs.Post)]
			public ActionResult Create(Colour colour)
			{
				if (ModelState.IsValid)
				{

					try
					{
						colour.Id = Guid.NewGuid();
						_colourRepository.Add(colour);
						_colourRepository.Save();


						return RedirectToAction("Details", new { id = colour.Id });
					}
					catch
					{
						ModelState.AddRuleViolations(colour.GetRuleViolations());
					}
				}

				return View(colour);
			}

			//
			// POST: /Country/Edit/xxx

			[AcceptVerbs(HttpVerbs.Post)]
			public ActionResult Edit(Guid id, FormCollection formValues)
			{
				Colour colour = _colourRepository.GetColour(id);

				try
				{

					UpdateModel(colour);
					_colourRepository.Save();

					return RedirectToAction("Details", new { id = colour.Id });
				}
				catch
				{
					ModelState.AddRuleViolations(colour.GetRuleViolations());

					return View(colour);
				}


			}

			//
			// HTTP POST: /Artists/Delete/xxx

			[AcceptVerbs(HttpVerbs.Post)]
			public ActionResult Delete(Guid id, string confirmButton)
			{

				Colour colour = _colourRepository.GetColour(id);

				if (colour == null)
					return View("NotFound");

				_colourRepository.Delete(colour);
				_colourRepository.Save();

				return View("Deleted");
			}

			#endregion

    }
}
